#include <sys/ptrace.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <unistd.h>
#include <sys/user.h>
#include <stdio.h>
#include <string.h>
#include <signal.h>
#include <sys/types.h>

#include "help_api.h"
#include "wrapper.h"
#include "hard_disk_controller.h"

int main(int argc, char** argv)
{
	if(argc<2) {
        printf("usage: %s [executable] [arg0] .. [argn]\n", argv[0]);
        return -2;
    }

    pid_t child;
    long orig_eax;
    child = fork();
    if(child == 0) {
        ptrace(PTRACE_TRACEME, 0, NULL, NULL);
        printf("Running %s\n", argv[1]);
        execv(argv[1], &(argv[2]));
    }
    else {    
        Wrapper wrap(child);
        try{
            wrap.run();
        }catch (int i)
        {
            error_print("Unhandled exception, terminating...\n");
            ptrace(PTRACE_KILL, child, 0, 0);
            ptrace(PTRACE_DETACH, child, 0, 0);
        }
    }

    return 0;
}

